//
// Created by 王筱童 on 2022/5/14.
//

#ifndef TINY_REDIS_SERVER_CMAKE_SAVE_MANEGER_H
#define TINY_REDIS_SERVER_CMAKE_SAVE_MANEGER_H
#include <fstream>
#include <filesystem>
#include <vector>
#include <string>
#include "asio.hpp"

class redis_server;
class save_maneger {
private:
    bool is_reload= false;
    bool is_rewirte= false;
    const std::filesystem::path save_path{"./save_data.dat"};
    const std::filesystem::path rewrite_path{"./rewrite_data.dat"};
    redis_server *server{};
    std::ofstream out;
    std::ifstream in;
public:
    explicit save_maneger(redis_server*_server);
    void rewirte();
    void save(const std::string&command,const std::vector<std::string>& args,std::size_t db_index);
    asio::awaitable<void> reload();
};


#endif //TINY_REDIS_SERVER_CMAKE_SAVE_MANEGER_H
